<?php
require_once('Zend/Db/Table/Abstract.php');

/**
 * Add your description here
 * 
 * @author 
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

class Default_Model_DbTable_ComponentUsage extends Zend_Db_Table_Abstract
{
        /**
         * $_name - name of database table
         *
         * @var string
         */
	protected $_name='component_usage';

        /**
         * $_id - this is the primary key of component_usage table
         *        int(11)         
         *
         * @var int         
         */
	protected $_id='id';

        /**
         * returns the list of components that are being used
         *
         * @return array
         */

        public function getUsedComponentsInfo() {

            $query=<<<QUERY
                select * from component_usage
                join components on component_usage.component_id = components.id
                where component_usage.enabled = 1
QUERY;

            $result=$this->getAdapter()->query($query)->fetchAll();
            return $result;
        }


        /**
         *
         * counts rows in the entire table
         *
         * @return int
         */
        public function countAllRows() {
            $query = $this->select()->from($this->_name, 'count(*) as all_count');
            $numRows = $this->fetchRow($query);
            return $numRows['all_count'];
        }

        /**
         *
         * deletes rows with matches component id
         *
         * @param int $id
         */

        public function deleteRowsByComponentId($id) {
            $this->delete('component_id = '.$id);
        }
}


